package akka;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.japi.pf.ReceiveBuilder;
import cn.hutool.core.lang.Console;

import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author : SandKing
 * @CreateDate : 2019/4/29 15:50
 * @Description ：Please describe this document
 */
public abstract class BaseActor extends AbstractActor {
    @Override
    public Receive createReceive() {
        return ReceiveBuilder.create()
                .match(AkkaAsk.class, ask -> {
                    if (ask.getResult() != null) {
                        ask.getCallback().accept(ask.getResult());
                    } else {
                        ask.setResult(ask.getFunction().apply(ask.getParameter()));
                        getSender().tell(ask, getSelf());
                    }
                }).match(Object.class, obj -> {
                    onReceive(obj);
                }).build();
    }

    public abstract void onReceive(Object obj);


}
